/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author juan
 */
public class Operaciones {
    
    public static int generar_a_Binario(int T)
    {
        int a;
        int index = (int) (2 * Math.random() +1);
        if(index==1)
            a = (8 * T) + 3;
        else
            a = (8 * T) - 3;
        return a;
     }
    
    public static int generar_a_Decimal(int T)
    {
        int a;
        int vector_Numeros[]= {3, 11, 13, 19, 21, 27, 29, 37, 53, 61, 67, 69, 77, 83, 91};
        int indice = (int) (14 * Math.random() +1);
        int Q = vector_Numeros[indice];
        
        int index = (int) (2 * Math.random() +1);
        if (index == 1)                    
            a = (200 * T) + Q;
        else
            a = (200 * T) - Q;
        return a;
     }
    
    public static int generar_m(int potencia, int valor_p_m)
    {
        int m;
        m = (int) Math.pow(potencia, valor_p_m);
        return m;
    }
    
    public static double generar_Numero(double semilla, int a, int c, int m)
    {
        double nuevo;
        nuevo= ((a * semilla) + c) % m;
        return nuevo;    
    }
        
    public static boolean escribir_Archivo(FileWriter writer, String contenido)
    {
        
        boolean res = false;
                
        try
        {
            writer.write(contenido);
            res = true;
            
        }
        catch (IOException ex)
        {
            System.out.println("Error de escritura" + ex.getMessage());     
            res = false;
        }
        
        return res;
    }
    
    public static void cerrar_Flujo(FileWriter writer)
    {
        try 
        {
            writer.close();
        } 
        catch (IOException ex) 
        {
            System.out.println("Error: " + ex.getMessage());
        }
    }
}
